# SA2410.ZCE

from app_config import get_pro
import re

pro = get_pro()


def to_chart(data: str):
    # SA2508	cj2508	1324	-0.97	-13
    strip = (str
             .strip()
             .replace('\t', ' '))
    strip = re.sub(r' +', ' ', strip)  # 将 1 个或多个空格替换为 1 个空格
    xdata = []
    ydata = []
    splitlines = strip.splitlines()
    for line in splitlines:
        print(line)
        lineArr = line.strip().split(' ')
        xdata.append(lineArr[0])
        ydata.append(int(lineArr[2]))

    # 计算平均值
    average = round(sum(ydata) / len(ydata))

    # 每个元素减去平均值
    result = [x - average for x in ydata]

    from pyecharts.charts import Bar
    from pyecharts.charts import Line
    from pyecharts.options import TitleOpts
    from datetime import datetime

    # 创建条形图
    bar = Bar()
    bar.add_xaxis(xdata)  # X 轴数据
    bar.add_yaxis("示例数据", ydata)  # Y 轴数据

    # 设置全局配置项
    bar.set_global_opts(title_opts=TitleOpts(title="日期示例"))

    # 渲染图表到 HTML 文件
    bar.render('date_example.html')

    line = Line()
    line.add_xaxis(xdata)
    line.add_yaxis(average.__str__() + ' / ' + datetime.now().strftime("%Y-%m-%d %H:%M:%S"), result)
    line.render("line.html")

    pass


if __name__ == '__main__':

    print(302/5245)



















#     str = """
#     SA2508	纯碱2508	1380	3.22%	43
# SA2509	纯碱2509	1391	3.11%	42
# SA2510	纯碱2510	1413	2.84%	39
# SA2511	纯碱2511	1423	2.74%	38
# SA2512	纯碱2512	1457	2.75%	39
# SA2601	纯碱2601	1464	3.54%	50
# SA2602	纯碱2602	1473	2.65%	38
# SA2603	纯碱2603	1472	3.30%	47
# SA2604	纯碱2604	1498	3.81%	55
# SA2605	纯碱2605	1500	3.16%	46
# SA2606	纯碱2606	1509	4.86%	70
# SA2607	纯碱2607	1503	3.02%	44"""
#
#     to_chart(str)
